package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: fanYuLe
 * @CreateTime: 2025-09-02  14:05
 * @Description: 死信交换机
 */
@Configuration
public class TTLConfig {

    //声明延迟交换机
    @Bean
    public FanoutExchange ttlFanout(){
      return new FanoutExchange("ttl.fanout");
    }

    //声明延迟队列
    @Bean
    public Queue ttlQueue(){
        return QueueBuilder
                .durable("ttl.queue")
                .deadLetterExchange("hmall.direct")
                .build();
    }

    //绑定队列和交换机
    @Bean
    public Binding bindingTtlQueueWithBlue(Queue ttlQueue, FanoutExchange ttlFanout){
        return BindingBuilder.bind(ttlQueue).to(ttlFanout);
    }
}
